<?php

function exit_array($data = array())
{
	echo json_encode($data);
	die;
}

function exit_ok($data = array())
{
	$data['success'] = true;
	echo json_encode($data);
	die;
}

function exit_error($msg = 'error')
{
	if (is_array($msg))
	{
		$arr = $msg;
		$arr['success'] = false;
	}
	else
	{
		$arr = array('success'=>false,'msg'=>$msg);
	}
	echo json_encode($arr);
	die;
}


function check_login()
{
	return isset($_SESSION['user']);
}

function save_settings($filename,$data)
{
	file_put_contents($filename,'<'.'?php return '.var_export($data,true).';');
}

function end_encode($s)
{
	return md5(base64_encode(md5($s.'aaabbbcccfdaf')));
}

function get_file_type($name)
{
	$ext = strtolower(array_pop(explode('.',$name)));
	return $ext;
}


